package com.dsg.kf.common.util;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;

/**
 * 
 * 
 * @author panguixiang
 * @version $Id: HttpUtil.java, v 0.1 2016年2月4日 下午2:53:18  Exp $
 */
public class HttpUtil {

    /**
     * httpclient发送get请求
     * @param url
     * @param data
     * @return
     */
    public static void sendGet(String url) throws Exception {
        HttpClient httpclient = new HttpClient();
        url += "?timer=" + System.currentTimeMillis();
        GetMethod method = new GetMethod(url);
        method.setRequestHeader("Connection", "close");
        method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);//请求超时时长
        try {
            httpclient.executeMethod(method);
        } catch (Exception e) {
            throw new Exception("发送http=== " + url + " , post请求发生系统异常===", e);
        } finally {
            if (method != null) {
                method.abort();
                method.releaseConnection();
            }
        }
    }
}
